package tools.vetorial;

import java.awt.Color;
import java.awt.event.KeyEvent;
import java.awt.event.MouseEvent;

import core.DrawContext;
import core.DrawTool;
import core.Object2D;

public abstract class PointSelectionTool extends DrawTool{

	private int lineSize = 1;
	
	private Color color = Color.black;
	
	private boolean fill = false;
	
	private int pointOrder = 0;
	
	@Override
	public void dispose(DrawContext ctx) {
		pencilUp(ctx);
		ctx.removeObject2d(getProxy());		
	}

	@Override
	public void init(DrawContext ctx) {
		pencilDown(ctx);
		ctx.addObject2d(getProxy());
	}
	
	@Override
	public void processKeyEvent(KeyEvent evt, DrawContext context) {
		// TODO Auto-generated method stub

	}
	
	@Override
	public void processMouseEvent(MouseEvent evt, DrawContext context) {
		
		switch(evt.getID()){
		case MouseEvent.MOUSE_CLICKED:
			
			if(evt.getButton() == MouseEvent.BUTTON3){ //Right button
				pointOrder = 0;
				pencilUp(context);
				pencilDown(context);
			}else if(evt.getButton() == MouseEvent.BUTTON1){ //Click
				mouseClick(evt, context);
			}
			
			break;
		case MouseEvent.MOUSE_MOVED:
			mouseMoved(evt, context);
			break;
		}
		
	}
	
	private void mouseClick(MouseEvent evt, DrawContext ctx){
		
		addPoint(evt.getX(), evt.getY(), pointOrder++, ctx);
		
		//Update screen
		ctx.setChanged(true);
	
	}
	
	private void mouseMoved(MouseEvent evt, DrawContext ctx){
		updateProxy(evt.getX(), evt.getY(), ctx);
		ctx.setChanged(true);
	}
	
	public abstract void addPoint(int x, int y, int order, DrawContext ctx);
	
	public abstract void updateProxy(int x, int y, DrawContext ctx);
	
	public abstract void pencilUp(DrawContext ctx);
	
	public abstract void pencilDown(DrawContext ctx);

	public int getLineSize() {
		return lineSize;
	}

	public void setLineSize(int lineSize) {
		this.lineSize = lineSize;
	}

	public Color getColor() {
		return color;
	}

	public void setColor(Color color) {
		this.color = color;
	}

	public boolean isFill() {
		return fill;
	}

	public void setFill(boolean fill) {
		this.fill = fill;
	}
	
	public abstract Object2D getProxy();
}
